package cn.qihua.model;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

/**
 * SysUser entity. @author MyEclipse Persistence Tools
 */

public class SysUser implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 5279606516962501435L;
	private Integer id;
	private Integer organizationId;
	private String roleIds;
	private String name;
	private String username;
	private String password;
	private String salt;
	private String phone;
	private String qq;
	private String hi;
	private String email;
	private Timestamp addDate;
	private Boolean locked;

	// private List<Integer> listId;

	// Constructors

	/** default constructor */
	public SysUser() {
	}

	/** full constructor */
	public SysUser(Integer organizationId, String roleIds, String name,
			String username, String password, String salt, String phone,
			String qq, String hi, String email, Timestamp addDate,
			Boolean locked) {
		this.organizationId = organizationId;
		this.roleIds = roleIds;
		this.name = name;
		this.username = username;
		this.password = password;
		this.salt = salt;
		this.phone = phone;
		this.qq = qq;
		this.hi = hi;
		this.email = email;
		this.addDate = addDate;
		this.locked = locked;
	}

	public SysUser(String username, String password) {
		this.username = username;
		this.password = password;
	}

	// Property accessors

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getOrganizationId() {
		return this.organizationId;
	}

	public void setOrganizationId(Integer organizationId) {
		this.organizationId = organizationId;
	}

	public String getRoleIds() {
		return this.roleIds;
	}

	public void setRoleIds(String roleIds) {
		this.roleIds = roleIds;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return this.salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getQq() {
		return this.qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getHi() {
		return this.hi;
	}

	public void setHi(String hi) {
		this.hi = hi;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@JSON(format = "yyyy-MM-dd HH:mm:ss")
	public Timestamp getAddDate() {
		return this.addDate;
	}

	public void setAddDate(Timestamp addDate) {
		this.addDate = addDate;
	}

	public Boolean getLocked() {
		return this.locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	public List<Integer> getListRoleIds() {
		List<Integer> listId = new ArrayList<Integer>();
		if (roleIds == null) {
			return listId;
		}
		String[] roleIdStrs = roleIds.split(",");
		
		for (String idStr : roleIdStrs) {
			if (idStr.isEmpty() || idStr.equals("")) {
				continue;
			}
			listId.add(Integer.valueOf(idStr));
		}
		return listId;
	}

	public String getCredentialsSalt() {
		// TODO Auto-generated method stub
		return username + salt;
	}

}